// 1. 导入 Vue 和 Vuex
import Vue from 'vue'
import Vuex from 'vuex'
// 2. 将 Vuex 安装为 Vue 的插件
Vue.use(Vuex)
// 3. 创建 Store 的实例对象
const store = new Vuex.Store({
	// 挂载 store 模块
	state: {
		hasLogin: false,
		userInfo: {
			id: '',
			openId: '',
			headImg: '',
			nickName: '',
			userMoney: 0,
			userphone: '',
			lookId: ''
		},
		statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
		safeAreaBottom: 0
	},
	mutations: {
		login(state, userInfo) {
			state.userInfo.id = userInfo.id || '';
			state.userInfo.openId = userInfo.openId || '';
			state.userInfo.headImg = userInfo.headImg || '';
			state.userInfo.nickName = userInfo.nickName || '';
			state.userInfo.userMoney = userInfo.userMoney || 0;
			state.userInfo.userphone = userInfo.userphone || '';
			state.userInfo.lookId = userInfo.lookId || '';
			state.hasLogin = true;
			uni.setStorageSync('userInfo', userInfo)
		},
		logout(state) {
			state.userInfo = {}
			state.hasLogin = false;
			uni.clearStorageSync('userInfo');
		},
		set_safe(state, safeAreaBottom) {
			state.safeAreaBottom = safeAreaBottom
		}
	}
})
// 向外共享 Store 的实例对象
export default store